import { UserInfo } from "@/api/user";

export const userKey = "user-info";
export const TokenKey = "token";

/** 获取`token` */
export function getToken(): string {
  return localStorage.getItem(TokenKey);
}

export function getUserInfo(): UserInfo {
  let strData = localStorage.getItem(userKey);
  return strData ? JSON.parse(strData) : {};
}

export function setToken(nekot: string) {
  localStorage.setItem(TokenKey, nekot);
}

export function setUserInfo(info: UserInfo) {
  localStorage.setItem(userKey, JSON.stringify(info));
}

/** 删除`token`以及key值为`user-info`的localStorage信息 */
export function removeToken() {
  localStorage.removeItem(TokenKey);
  localStorage.removeItem(userKey);
}

/** 格式化token（jwt格式） */
export const formatToken = (token: string): string => {
  return token;
};
